home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / expr11.zip / EXPR.DOC next >
Text File  |  1992-02-26  |  8KB  |  301 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.                                    EXPR.LIB
  16.  
  17.                         An expression library for Turbo C
  18.  
  19.                                  Version 1.1
  20.  
  21.                                 Copyright 1992
  22.  
  23.                                  Dan Schikore
  24.                               1983 Greenheath Dr.
  25.                              Florissant, MO 63033
  26.  
  27.                               All Rights Reserved
  28.  
  29.                                February 26, 1992
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.                 Turbo C is a copyright of Borland International
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43. Table of Contents
  44. -----------------
  45.  
  46. Introduction ....................... page 1
  47.  
  48. Disclaimer ......................... page 1
  49.  
  50. Shareware Notice ................... page 1
  51.  
  52. What is an expression? ............. page 2
  53.  
  54. Using the Library .................. page 3
  55.  
  56. Function Summaries ................. page 4 - 6
  57.  
  58.  
  59.                                 - 1 -
  60.  
  61.  
  62. Introduction
  63. ------------
  64. Expr.lib is a library of Turbo C functions to create and perform operations
  65. on expressions of one or more variables.  The capabilities of the functions
  66. include:
  67.  
  68.    . Parsing equations from strings
  69.    . Unparsing an equation into a string
  70.    . Simplifying an equation
  71.    . Copying equations
  72.    . Differentiating with respect to a variable
  73.    . Multiplying, Dividing, Adding, or Subtracting two equations
  74.    . Evaluating the expression for given variable values
  75.  
  76.  
  77.  
  78.  
  79. Disclaimer
  80. ----------
  81. The author of expr.lib provides no warranties or guarantees concerning the
  82. functionality of this library or its suitability for any purpose.
  83.  
  84.  
  85.  
  86.  
  87. Shareware Notice
  88. ----------------
  89. This expression library is shareware.  If you try it, and would like to
  90. continue using it, you should register.  Registration for personal use
  91. is $10.  Registration for any other use is $25.  The source for the current
  92. version will be included for an additional $25.  Please fill out the document
  93. 'register.doc' and send along with check or money order to:
  94.  
  95.     Dan Schikore
  96.     1983 Greenheath Dr.
  97.     Florissant, MO 63033
  98.  
  99.  
  100.                                 - 2 -
  101.  
  102. What is an expression?
  103. ----------------------
  104.  
  105. Expressions supported by Expr.lib are typical mathematical expressions
  106. including constants, real numbers, variables, functions, and all
  107. mathematical operators.
  108.  
  109. Constants:
  110.  
  111.     E = 2.718281828
  112.     PI = 3.1415926535
  113.  
  114. Variables:
  115.  
  116.     Expr.lib supports equations of any variables, to be specified
  117. by the programmer.  Variables are assumed to be alphabetic, and are
  118. not case-sensitive.
  119.  
  120. Functions:
  121.  
  122.     COS SIN TAN CSC SEC COT
  123.     COSH SINH TANH CSCH SECH COTH
  124.     SQRT LOG LN EXP
  125.  
  126. Operators:
  127.  
  128.     Addition (+)
  129.     Subtraction (-)
  130.     Multiplication (*)
  131.     Division (/)
  132.     Negation (-)
  133.     Exponentiation (^)
  134.     Parenthesis may be used to define precedence
  135.  
  136.  
  137.                                 - 3 -
  138.  
  139. Using the Library
  140. -----------------
  141.  
  142. Expr.lib is a Turbo C function library created with Turbo C Version 2.0,
  143. compiled with the huge memory model.  The only new data type needed by
  144. the programmer is a structure called 'Expr'.  The necessary definitions
  145. for the new data structures are in the file, 'expr.h'.  To use expr.lib,
  146. you should first place the file 'expr.h' in your include file directory,
  147. and place 'expr.lib' in your library directory. In programs which use
  148. expr.lib, put the following line with the other #include statements near
  149. the beginning of the program:
  150.  
  151. #include <expr.h>
  152.  
  153. Expressions are parsed from character strings and placed into these
  154. structures.  To parse an expression from the command line, use the
  155. following declarations and calls:
  156.  
  157.     Expr *expr;                /* declare an expression variable */
  158.     expr=ParseExpr(argv[1]);   /* parse the expr. from command line */
  159.  
  160. Once an equation has been parsed, many things can be done to it.  First,
  161. you can reverse the process and get a string from the parsed expression.
  162. To add to the above example, the following line would print out the
  163. parsed expression:
  164.  
  165.     printf("parsed expression: %s\n",UnParseExpr(expr));
  166.  
  167. A more detailed User Reference to the functions follows on the next page.
  168.  
  169. For an example of how to use these and other functions, see the program
  170. 'parse.c' included in the archive.  To compile the example program,
  171. type 'tcc -mh parse.c expr.lib' at the DOS prompt.
  172.  
  173.                                 - 4 -
  174.  
  175. The Functions
  176. -------------
  177.  
  178. -------------------------------------------------------------------------
  179. FUNCTION: ParseExpr
  180.  
  181. DECLARATION: Expr *ParseExpr(char *, int, char *)
  182.  
  183. USE: Parses an expression from the first argument string.  The second
  184.      argument is the number of variable in the equation, and the third
  185.      is an array listing the variables.
  186.  
  187. RETURN VALUE: An Expr pointer if a valid expression was parsed. On error,
  188.               NULL is returned, and a brief description of the cause of
  189.               the error is in the string Eqn_errstr.  This string should
  190.               not be freed in the user program.
  191.  
  192. -------------------------------------------------------------------------
  193. FUNCTION: UnParseExpr
  194.  
  195. DECLARATION: char *UnParseExpr(Expr *)
  196.  
  197. USE: Un-parses the given equation into a string.
  198.  
  199. RETURN VALUE: A character string containing the un-parsed form of
  200.               the equation.  This string is dynamically allocated
  201.               by UnParseExpr and should be freed when it is no longer
  202.               needed.
  203.  
  204. -------------------------------------------------------------------------
  205. FUNCTION: SimpExpr
  206.  
  207. DECLARATION: void SimpExpr(Expr *)
  208.  
  209. USE: Simplifies the given expression.
  210.  
  211. RETURN VALUE: none.
  212.  
  213. -------------------------------------------------------------------------
  214. FUNCTION: DiffExpr
  215.  
  216. DECLARATION: Expr *DiffExpr(Expr *, char)
  217.  
  218. USE: Differentiates the given expression, which respect to the given
  219.      variable.
  220.  
  221. RETURN VALUE: An Expr pointer giving the differentiated equation.
  222.  
  223. -------------------------------------------------------------------------
  224.  
  225.                                 - 5 -
  226.  
  227.  
  228. -------------------------------------------------------------------------
  229. FUNCTION: CopyExpr
  230.  
  231. DECLARATION: Expr *CopyExpr(Expr *)
  232.  
  233. USE: Copies the given expression into an identical structure.
  234.  
  235. RETURN VALUE: A pointer to the new expression structure.
  236.  
  237. -------------------------------------------------------------------------
  238. FUNCTION: EvalExpr
  239.  
  240. DECLARATION: double EvalExpr(Expr *, double *)
  241.  
  242. USE: Evaluates the given expression for the given values of the variables.
  243.  
  244. RETURN VALUE: The result of evaluating the expression.
  245.  
  246. -------------------------------------------------------------------------
  247. FUNCTION: FreeExpr
  248.  
  249. DECLARATION: void FreeExpr(Expr *)
  250.  
  251. USE: frees all memory associated with the given expression.  The pointer
  252.      passed to this function is no longer valid.
  253.  
  254. RETURN VALUE: None.
  255.  
  256. -------------------------------------------------------------------------
  257. FUNCTION: AddExpr
  258.  
  259. DECLARATION: Expr *AddExpr(Expr *, Expr *)
  260.  
  261. USE: Adds the two expression arguments.  These expressions should be
  262.      created using the same variables.
  263.  
  264. RETURN VALUE: A pointer to a new expression containing the sum.
  265.  
  266. -------------------------------------------------------------------------
  267. FUNCTION: SubExpr
  268.  
  269. DECLARATION: Expr *SubExpr(Expr *, Expr *)
  270.  
  271. USE: Subtracts the second expression from the first.  These expressions
  272.      should be created using the same variables.
  273.  
  274. RETURN VALUE: A pointer to a new expression containing the difference.
  275.  
  276. -------------------------------------------------------------------------
  277. FUNCTION: DivExpr
  278.  
  279. DECLARATION: Expr *DivExpr(Expr *, Expr *)
  280.  
  281. USE: Divides the first expression by the second expression.  These
  282.      expressions should be created using the same variables.
  283.  
  284. RETURN VALUE: A pointer to a new expression containing the quotient.
  285.  
  286. -------------------------------------------------------------------------
  287.  
  288.                                 - 6 -
  289.  
  290. -------------------------------------------------------------------------
  291. FUNCTION: MultExpr
  292.  
  293. DECLARATION: Expr *MultExpr(Expr *, Expr *)
  294.